home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Science⁄Math
/
Gnuplot 3.5 for Macintosh
/
SOURCES 3.5
/
term
/
post.trm
< prev
next >
Wrap
Text File
|
1993-11-12
|
11KB
|
434 lines
/*
* $Id: post.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
*/
/* GNUPLOT - post.trm */
/*
* Copyright (C) 1990 - 1993
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the modified code. Modifications are to be distributed
* as patches to released version.
*
* This software is provided "as is" without express or implied warranty.
*
* This file is included by ../term.c.
*
* This terminal driver supports:
* postscript
*
* AUTHORS
* Russell Lang
*
* send your comments or suggestions to (info-gnuplot@dartmouth.edu).
*
* The 'postscript' driver produces landscape output 10" wide and 7" high.
* To change font to Times-Roman and font size to 20pts use
* 'set term postscript "Times-Roman" 20'.
* To get a smaller (5" x 3.5") eps output use 'set term post eps'
* and make only one plot per file. Font size for eps will be half
* the specified size.
*/
/* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
char ps_font[MAX_ID_LEN+1] = "Helvetica" ; /* name of font */
int ps_fontsize = 14; /* size of font in pts */
TBOOLEAN ps_portrait = FALSE; /* vertical page */
TBOOLEAN ps_color = FALSE;
TBOOLEAN ps_solid = FALSE; /* use solid lines */
TBOOLEAN ps_eps = FALSE; /* Is this for an eps file? */
/* Added by Robert Davis <davis@ecn.purdue.edu> */
int ps_page=0; /* page count */
int ps_path_count=0; /* count of lines in path */
int ps_ang=0; /* text angle */
enum JUSTIFY ps_justify=LEFT; /* text is flush left */
char GPFAR * GPFAR PS_header[] = {
"/M {moveto} bind def\n",
"/L {lineto} bind def\n",
"/R {rmoveto} bind def\n",
"/V {rlineto} bind def\n",
"/vpt2 vpt 2 mul def\n",
"/hpt2 hpt 2 mul def\n",
/* flush left show */
"/Lshow { currentpoint stroke M\n",
" 0 vshift R show } def\n",
/* flush right show */
"/Rshow { currentpoint stroke M\n",
" dup stringwidth pop neg vshift R show } def\n",
/* centred show */
"/Cshow { currentpoint stroke M\n",
" dup stringwidth pop -2 div vshift R show } def\n",
/* Dash or Color Line */
"/DL { Color {setrgbcolor Solid {pop []} if 0 setdash }\n",
" {pop pop pop Solid {pop []} if 0 setdash} ifelse } def\n",
/* Border Lines */
"/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
/* Axes Lines */
"/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
/* Plot Lines */
"/PL { stroke gnulinewidth setlinewidth } def\n",
/* Line Types */
"/LTb { BL [] 0 0 0 DL } def\n", /* border */
"/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
"/LT0 { PL [] 0 1 0 DL } def\n",
"/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
"/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
"/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
"/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
"/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
"/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
"/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
"/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
"/P { stroke [] 0 setdash\n", /* Point */
" currentlinewidth 2 div sub M\n",
" 0 currentlinewidth V stroke } def\n",
"/D { stroke [] 0 setdash 2 copy vpt add M\n", /* Diamond */
" hpt neg vpt neg V hpt vpt neg V\n",
" hpt vpt V hpt neg vpt V closepath stroke\n",
" P } def\n",
"/A { stroke [] 0 setdash vpt sub M 0 vpt2 V\n", /* Plus (Add) */
" currentpoint stroke M\n",
" hpt neg vpt neg R hpt2 0 V stroke\n",
" } def\n",
"/B { stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M\n", /* Box */
" 0 vpt2 neg V hpt2 0 V 0 vpt2 V\n",
" hpt2 neg 0 V closepath stroke\n",
" P } def\n",
"/C { stroke [] 0 setdash exch hpt sub exch vpt add M\n", /* Cross */
" hpt2 vpt2 neg V currentpoint stroke M\n",
" hpt2 neg 0 R hpt2 vpt2 V stroke } def\n",
"/T { stroke [] 0 setdash 2 copy vpt 1.12 mul add M\n", /* Triangle */
" hpt neg vpt -1.62 mul V\n",
" hpt 2 mul 0 V\n",
" hpt neg vpt 1.62 mul V closepath stroke\n",
" P } def\n",
"/S { 2 copy A C} def\n", /* Star */
NULL
};
#define PS_XOFF 50 /* page offset in pts */
#define PS_YOFF 50
#define PS_XMAX 7200
#define PS_YMAX 5040
#define PS_XLAST (PS_XMAX - 1)
#define PS_YLAST (PS_YMAX - 1)
#define PS_VTIC (PS_YMAX/80)
#define PS_HTIC (PS_YMAX/80)
#define PS_SC (10) /* scale is 1pt = 10 units */
#define PS_LW (0.5*PS_SC) /* linewidth = 0.5 pts */
#define PS_VCHAR (14*PS_SC) /* default is 14 point characters */
#define PS_HCHAR (14*PS_SC*6/10)
int PS_pen_x, PS_pen_y;
int PS_taken;
int PS_linetype_last;
TBOOLEAN PS_relative_ok;
PS_options()
{
extern struct value *const_express();
extern double real();
if (!END_OF_COMMAND) {
if (almost_equals(c_token,"p$ortrait")) {
ps_portrait=TRUE;
ps_eps=FALSE;
c_token++;
}
else if (almost_equals(c_token,"l$andscape")) {
ps_portrait=FALSE;
ps_eps=FALSE;
c_token++;
}
else if (almost_equals(c_token,"e$psf")) {
ps_portrait=TRUE;
ps_eps = TRUE;
c_token++;
}
else if (almost_equals(c_token,"d$efault")) {
ps_portrait=FALSE;
ps_eps=FALSE;
ps_color=FALSE;
strcpy(ps_font,"Helvetica");
ps_fontsize = 14;
term_tbl[term].v_char = (unsigned int)(ps_fontsize*PS_SC);
term_tbl[term].h_char = (unsigned int)(ps_fontsize*PS_SC*6/10);
c_token++;
}
}
if (!END_OF_COMMAND) {
if (almost_equals(c_token,"m$onochrome")) {
ps_color=FALSE;
c_token++;
}
else if (almost_equals(c_token,"c$olor")) {
ps_color=TRUE;
c_token++;
}
}
if (!END_OF_COMMAND) {
if (almost_equals(c_token,"s$olid")) {
ps_solid=TRUE;
c_token++;
}
else if (almost_equals(c_token,"d$ashed")) {
ps_solid=FALSE;
c_token++;
}
}
if (!END_OF_COMMAND && isstring(c_token)) {
quote_str(ps_font,c_token);
c_token++;
}
if (!END_OF_COMMAND) {
/* We have font size specified */
struct value a;
ps_fontsize = (int)real(const_express(&a));
term_tbl[term].v_char = (unsigned int)(ps_fontsize*PS_SC);
term_tbl[term].h_char = (unsigned int)(ps_fontsize*PS_SC*6/10);
}
sprintf(term_options,"%s %s %s \"%s\" %d",
ps_eps ? "eps" : (ps_portrait ? "portrait" : "landscape"),
ps_color ? "color" : "monochrome",
ps_solid ? "solid" : "dashed",
ps_font,ps_fontsize);
}
PS_init()
{
static char GPFAR psi1[] = "%%%%Creator: gnuplot\n\
%%%%DocumentFonts: %s\n\
%%%%BoundingBox: %d %d ";
static char GPFAR psi2[] = "%%%%EndComments\n\
/gnudict 40 dict def\ngnudict begin\n\
/Color %s def\n\
/Solid %s def\n\
/gnulinewidth %.3f def\n\
/vshift %d def\n\
/dl {%d mul} def\n\
/hpt %.1f def\n\
/vpt %.1f def\n";
struct termentry *t = &term_tbl[term];
int i;
ps_page = 0;
if (!ps_eps)
fprintf(outfile,"%%!PS-Adobe-2.0\n");
else
fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-2.0\n");
fprintf(outfile, psi1, ps_font, PS_XOFF, PS_YOFF);
if (ps_portrait)
fprintf(outfile,"%d %d\n",
(int)(xsize*(ps_eps ? 0.5 : 1.0)*(PS_XMAX)/PS_SC+0.5+PS_XOFF),
(int)(ysize*(ps_eps ? 0.5 : 1.0)*(PS_YMAX)/PS_SC+0.5+PS_YOFF) );
else
fprintf(outfile,"%d %d\n",
(int)(ysize*(ps_eps ? 0.5 : 1.0)*(PS_YMAX)/PS_SC+0.5+PS_XOFF),
(int)(xsize*(ps_eps ? 0.5 : 1.0)*(PS_XMAX)/PS_SC+0.5+PS_YOFF) );
if (!ps_eps)
fprintf(outfile,"%%%%Pages: (atend)\n");
fprintf(outfile, psi2,
ps_color ? "true" : "false",
ps_solid ? "true" : "false",
PS_LW, /* line width */
(int)(t->v_char)/(-3), /* shift for vertical centring */
PS_SC, /* dash length */
PS_HTIC/2.0, /* half point width */
PS_VTIC/2.0); /* half point height */
for ( i=0; PS_header[i] != NULL; i++)
fprintf(outfile,"%s",PS_header[i]);
fprintf(outfile,"end\n%%%%EndProlog\n");
}
PS_graphics()
{
static char GPFAR psg1[] = "0 setgray\n/%s findfont %d scalefont setfont\nnewpath\n";
struct termentry *t = &term_tbl[term];
ps_page++;
if (!ps_eps)
fprintf(outfile,"%%%%Page: %d %d\n",ps_page,ps_page);
fprintf(outfile,"gnudict begin\ngsave\n");
fprintf(outfile,"%d %d translate\n",PS_XOFF,PS_YOFF);
fprintf(outfile,"%.3f %.3f scale\n", (ps_eps ? 0.5 : 1.0)/PS_SC,
(ps_eps ? 0.5 : 1.0)/PS_SC);
if (!ps_portrait) {
fprintf(outfile,"90 rotate\n0 %d translate\n", (int)(-PS_YMAX*ysize));
}
fprintf(outfile, psg1, ps_font, (t->v_char) );
ps_path_count = 0;
PS_relative_ok = FALSE;
PS_pen_x = PS_pen_y = -4000;
PS_taken = 0;
PS_linetype_last = -1;
}
PS_text()
{
ps_path_count = 0;
fprintf(outfile,"stroke\ngrestore\nend\nshowpage\n");
/* fprintf(stderr,"taken %d times\n",PS_taken); */
/* informational: tells how many times it was "cheaper"
to do a relative moveto or lineto rather than an
absolute one */
}
PS_reset()
{
fprintf(outfile,"%%%%Trailer\n");
if (!ps_eps)
fprintf(outfile,"%%%%Pages: %d\n",ps_page);
}
PS_linetype(linetype)
int linetype;
{
char *line = "ba012345678";
linetype = (linetype % 9) + 2;
PS_relative_ok = FALSE;
if (PS_linetype_last == linetype) return(0);
PS_linetype_last = linetype;
fprintf(outfile,"LT%c\n", line[linetype]);
ps_path_count = 0;
}
PS_move(x,y)
unsigned int x,y;
{
int dx, dy;
char abso[20],rel[20];
dx = x - PS_pen_x;
dy = y - PS_pen_y;
/* can't cancel all null moves--need a move after stroke'ing */
if (dx==0 && dy==0 && PS_relative_ok)
return(0);
sprintf(abso, "%d %d M\n", x, y);
sprintf(rel, "%d %d R\n", dx, dy);
if (strlen(rel) < strlen(abso) && PS_relative_ok){
fputs(rel, outfile);
PS_taken++;
}else
fputs(abso, outfile);
PS_relative_ok = TRUE;
ps_path_count += 1;
PS_pen_x = x;
PS_pen_y = y;
}
PS_vector(x,y)
unsigned int x,y;
{
int dx, dy;
char abso[20],rel[20];
dx = x - PS_pen_x;
dy = y - PS_pen_y;
if (dx==0 && dy==0) return(0);
sprintf(abso, "%d %d L\n", x, y);
sprintf(rel, "%d %d V\n", dx, dy);
if (strlen(rel) < strlen(abso) && PS_relative_ok){
fputs(rel, outfile);
PS_taken++;
}else
fputs(abso, outfile);
PS_relative_ok = TRUE;
ps_path_count += 1;
PS_pen_x = x;
PS_pen_y = y;
if (ps_path_count >= 400) {
fprintf(outfile,"currentpoint stroke M\n");
ps_path_count = 0;
}
}
PS_put_text(x,y,str)
unsigned int x, y;
char *str;
{
char ch;
if (!strlen(str)) return(0);
PS_move(x,y);
if (ps_ang != 0)
fprintf(outfile,"currentpoint gsave translate %d rotate 0 0 M\n"
,ps_ang*90);
putc('(',outfile);
ch = *str++;
while(ch!='\0') {
if ( (ch=='(') || (ch==')') || (ch=='\\') )
putc('\\',outfile);
putc(ch,outfile);
ch = *str++;
}
switch(ps_justify) {
case LEFT : fprintf(outfile,") Lshow\n");
break;
case CENTRE : fprintf(outfile,") Cshow\n");
break;
case RIGHT : fprintf(outfile,") Rshow\n");
break;
}
if (ps_ang != 0)
fprintf(outfile,"grestore\n");
ps_path_count = 0;
PS_relative_ok = FALSE;
}
int PS_text_angle(ang)
int ang;
{
ps_ang=ang;
return TRUE;
}
#ifdef THINK_C
int PS_justify_text(enum JUSTIFY mode)
#else
int PS_justify_text(mode)
enum JUSTIFY mode;
#endif
{
ps_justify=mode;
return TRUE;
}
/* postscript point routines */
PS_point(x,y,number)
int x,y;
int number;
{
char *point = "PDABCTS";
number %= POINT_TYPES;
if (number < -1)
number = -1; /* negative types are all 'dot' */
fprintf(outfile,"%d %d %c\n", x, y, point[number+1]);
PS_relative_ok = 0;
ps_path_count = 0;
PS_linetype_last = -1; /* force next linetype change */
}